package com.wjy.qs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjy.common.annotation.RunTime;
import com.wjy.qs.entity.Author;
import com.wjy.qs.mapper.AuthorMapper;
import com.wjy.qs.service.IAuthorService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ybxxszl
 * @since 2019-02-21
 */
@Service
public class AuthorServiceImpl extends ServiceImpl<AuthorMapper, Author> implements IAuthorService {

    @Resource
    private AuthorMapper authorMapper;

    // @CachePut(cacheNames = "insertAuthor", key = "#author.authorId")
    @Override
    public void insertAuthor(Author author) {
        author.setAuthorState(0);
        author.setLogicDelete(0);
        author.setVersion(0);
        authorMapper.insert(author);
    }

    // @CachePut(cacheNames = "updateAuthor", key = "#author.authorId")
    @Override
    public void updateAuthor(Author author) {
        author.setAuthorState(0);
        authorMapper.updateById(author);
    }

    // @CacheEvict(cacheNames = "deleteAuthor", key = "#authorId")
    @Override
    public void deleteAuthor(String authorId) {
        authorMapper.deleteById(authorId);
    }

    @Cacheable(cacheNames = "selectAuthor", key = "#authorId", sync = true)
    @RunTime(value = "选择作者", ignore = true)
    @Override
    public Author selectAuthor(String authorId) {
        return authorMapper.selectById(authorId);
    }

    @Cacheable(cacheNames = "selectAuthorList", sync = true)
    @RunTime(value = "选择作者列表", ignore = false)
    @Override
    public List<Author> selectAuthorList() {
        return authorMapper.selectList(null);
    }

}
